from ogreEx.axis import AXIS_MODES
from ogreEx.blender.props import IntProperty, StringProperty, EnumProperty, BoolProperty, FloatProperty
from ogreEx.blender.types import Operator
from ogreEx.config import getConfig
from ogreEx.constants import _IMAGE_FORMATS
from ogreEx.ogre.C_OgreCommonExport_ import _OgreCommonExport_
from ogreEx.ui.UIClass import MINI

@MINI
class INFO_OT_createOgreExport(Operator, _OgreCommonExport_):

    '''Export Ogre Scene'''

    bl_idname = "ogre.export"
    bl_label = "Export Ogre"
    bl_options = {'REGISTER'}

    # Basic options
    EX_SWAP_AXIS = EnumProperty(
        items=AXIS_MODES,
        name='swap axis',
        description='axis swapping mode',
        default= getConfig()['SWAP_AXIS']
    )
    EX_SEP_MATS = BoolProperty(
        name="Separate Materials",
        description="exports a .material for each material (rather than putting all materials in a single .material file)",
        default=getConfig()['SEP_MATS'])
    EX_ONLY_DEFORMABLE_BONES = BoolProperty(
        name="Only Deformable Bones",
        description="only exports bones that are deformable. Useful for hiding IK-Bones used in Blender. Warning: Will cause trouble if a deformable bone has a non-deformable parent",
        default=getConfig()['ONLY_DEFORMABLE_BONES'])        
    EX_ONLY_ANIMATED_BONES = BoolProperty(
        name="Only Animated Bones",
        description="only exports bones that have been keyframed, useful for run-time animation blending (example: upper/lower torso split)",
        default=getConfig()['ONLY_ANIMATED_BONES'])
    EX_SCENE          = BoolProperty(name="Export Scene"              ,description="export current scene (OgreDotScene xml)"                 ,default=getConfig()['SCENE'          ])
    EX_SELONLY        = BoolProperty(name="Export Selected Only"      ,description="export selected"                                         ,default=getConfig()['SELONLY'        ])
    EX_FORCE_CAMERA   = BoolProperty(name="Force Camera"              ,description="export active camera"                                    ,default=getConfig()['FORCE_CAMERA'   ])
    EX_FORCE_LAMPS    = BoolProperty(name="Force Lamps"               ,description="export all lamps"                                        ,default=getConfig()['FORCE_LAMPS'    ])
    EX_MESH           = BoolProperty(name="Export Meshes"             ,description="export meshes"                                           ,default=getConfig()['MESH'           ])
    EX_MESH_OVERWRITE = BoolProperty(name="Export Meshes (overwrite)" ,description="export meshes (overwrite existing files)"                ,default=getConfig()['MESH_OVERWRITE' ])
    EX_ARM_ANIM       = BoolProperty(name="Armature Animation"        ,description="export armature animations - updates the .skeleton file" ,default=getConfig()['ARM_ANIM'       ])
    EX_SHAPE_ANIM     = BoolProperty(name="Shape Animation"           ,description="export shape animations - updates the .mesh file"        ,default=getConfig()['SHAPE_ANIM'     ])
    EX_INDEPENDENT_ANIM = BoolProperty(
        name="Independent Animations",
        default=getConfig()['INDEPENDENT_ANIM'],
        description="Export each NLA-Strip independently. If unchecked NLA-Strips that overlap influence each other."
        )
    EX_TRIM_BONE_WEIGHTS = FloatProperty(
        name="Trim Weights",
        description="ignore bone weights below this value (Ogre supports 4 bones per vertex)",
        min=0.0, max=0.5, default=getConfig()['TRIM_BONE_WEIGHTS'] )
    EX_ARRAY = BoolProperty(name="Optimize Arrays", description="optimize array modifiers as instances (constant offset only)", default=getConfig()['ARRAY'])
    EX_MATERIALS = BoolProperty(name="Export Materials", description="exports .material script", default=getConfig()['MATERIALS'])
    EX_FORCE_IMAGE_FORMAT = EnumProperty( items=_IMAGE_FORMATS, name='Convert Images',  description='convert all textures to format', default=getConfig()['FORCE_IMAGE_FORMAT'] )
    EX_DDS_MIPS = IntProperty(name="DDS Mips", description="number of mip maps (DDS)", min=0, max=16, default=getConfig()['DDS_MIPS'])

    # Mesh options
    EX_lodLevels            = IntProperty    (name="LOD Levels"             ,description="MESH number of LOD levels"                      ,min=0 ,max=    32 ,default=getConfig()['lodLevels'            ])
    EX_lodDistance          = IntProperty    (name="LOD Distance"           ,description="MESH distance increment to reduce LOD"          ,min=0 ,max=  2000 ,default=getConfig()['lodDistance'          ])
    EX_lodPercent           = IntProperty    (name="LOD Percentage"         ,description="LOD percentage reduction"                       ,min=0 ,max=    99 ,default=getConfig()['lodPercent'           ])
    EX_nuextremityPoints    = IntProperty    (name="Extremity Points"       ,description="MESH Extremity Points"                          ,min=0 ,max= 65536 ,default=getConfig()['nuextremityPoints'    ])
    EX_generateEdgeLists    = BoolProperty   (name="Edge Lists"             ,description="MESH generate edge lists (for stencil shadows)"                    ,default=getConfig()['generateEdgeLists'    ])
    EX_generateTangents     = BoolProperty   (name="Tangents"               ,description="MESH generate tangents"                                            ,default=getConfig()['generateTangents'     ])
    EX_tangentSemantic      = StringProperty (name="Tangent Semantic"       ,description="MESH tangent semantic"                          ,maxlen=3          ,default=getConfig()['tangentSemantic'      ])
    EX_tangentUseParity     = IntProperty    (name="Tangent Parity"         ,description="MESH tangent use parity"                        ,min=0 ,max=    16 ,default=getConfig()['tangentUseParity'     ])
    EX_tangentSplitMirrored = BoolProperty   (name="Tangent Split Mirrored" ,description="MESH split mirrored tangents"                                      ,default=getConfig()['tangentSplitMirrored' ])
    EX_tangentSplitRotated  = BoolProperty   (name="Tangent Split Rotated"  ,description="MESH split rotated tangents"                                       ,default=getConfig()['tangentSplitRotated'  ])
    EX_reorganiseBuffers    = BoolProperty   (name="Reorganise Buffers"     ,description="MESH reorganise vertex buffers"                                    ,default=getConfig()['reorganiseBuffers'    ])
    EX_optimiseAnimations   = BoolProperty   (name="Optimize Animations"    ,description="MESH optimize animations"                                          ,default=getConfig()['optimiseAnimations'   ])

    filepath= StringProperty(name="File Path", description="Filepath used for exporting Ogre .scene file", maxlen=1024, default="", subtype='FILE_PATH')
    EXPORT_TYPE = 'OGRE'